addpath([pwd,"/lib"]);
addpath([pwd,"/src"]);

load("rec.dat");
load("tstl.dat");

stats=[rec, tstl];

scores=[];
iterations = 10;
startTime = cputime;
confidenceLevel=0.965;

for(trial=1:iterations)
	[trainSet testSet]  = splitSet(stats, 0.9);
	
	credibilityMatrix	= getPerformanceMatrix(trainSet);
	testAnswers = maxCredibilityAnswer(testSet(:,1:end-1), credibilityMatrix, 0.98);
	
	confMatrices = getConfusionMatrices(trainSet(:,1:end-1), trainSet(:,end));
	[testAnswers confidence] = bayesianMeta(testSet(:,1:end-1), confMatrices); 

	testAnswers(confidence<confidenceLevel)=10;
	
	scores=[scores; sum(testAnswers==testSet(:,6))/size(testSet,1), sum(testAnswers==10)/size(testSet,1)];
	printf("Last-> score	: %f, discarded: %f \n",scores(size(scores,1),1),scores(size(scores,1),2));
	printf("Mean-> score : %f, discarded: %f \n",mean(scores(:,1)),mean(scores(:,2)));
	fflush(stdout);
	
end;

printf("Average over %d iterations -> score: %f, discarded: %f \n", iterations, mean(scores(:,1)), mean(scores(:,2)));
